package com.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.service.UserManager;

public class RoleController extends UniversalController {
	private UserManager userManager;

	public UserManager getUserManager() {
		return userManager;
	}
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}
	public ModelAndView getViewRole(HttpServletRequest request,
			HttpServletResponse response){
		return new ModelAndView("role");
	}
	public ModelAndView getViewRoleMenu(HttpServletRequest request,
			HttpServletResponse response){
		return new ModelAndView("roleMenu");
	}
	public ModelAndView getListRoleTree(HttpServletRequest request,
			HttpServletResponse response) throws IllegalAccessException, InvocationTargetException {
		String code=request.getParameter("code");
		Map map = new HashMap();
		List list = null;
		list=this.userManager.getListRoleTree(code);
		getMessage(response,getJsonFromJSONArray(list));
		return null;
	}
	public ModelAndView saveRoleMenuTree(HttpServletRequest request,
			HttpServletResponse response) throws IllegalAccessException, InvocationTargetException {
		String roleCode=request.getParameter("roleCode");
		String menuCodes=request.getParameter("menuCodes");
		Map map = new HashMap();
		List list = null;
		userManager.saveRoleMenuTree(roleCode,menuCodes);
		map.put("success",true);
		getMessage(response,getJsonFromJSONArray(map));
		return null;
	}
}
